package com.group.project.hrms.utils;

import com.group.project.hrms.entity.AttendanceGroupInfo;
import com.group.project.hrms.entity.AttendanceShiftInfo;
import com.group.project.hrms.service.IAttendanceGroupInfoService;
import com.group.project.hrms.service.IAttendanceShiftInfoService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 该类是除登录认证外的所有验证方法的集合
 */
public class VerificationUtil {

    @Autowired
    private IAttendanceGroupInfoService iAttendanceGroupInfoService;

    @Autowired
    private IAttendanceShiftInfoService iAttendanceShiftInfoService;



    /**
     * 检查CheckPointInfo对象是否可以被删除
     * @param cid
     * @return true为可以删除（没有被引用），false为不能删除（被引用中）
     */
    public boolean confirmDeleteCheckPoint(String cid){
        List<AttendanceGroupInfo> groupInfoList = iAttendanceGroupInfoService.selectAllAttendanceGroupInfo();
        List<AttendanceShiftInfo> shiftInfoList = iAttendanceShiftInfoService.selectAllAttendanceShiftInfo();
        for (AttendanceGroupInfo ag : groupInfoList
             ) {
            String checkPointIds = ag.getCheckPointIds();
            if(checkPointIds.contains(cid)){
                return false;
            }
        }
        for (AttendanceShiftInfo as : shiftInfoList
             ) {
            String checkPointIdsStart = as.getStartCheckPointId();
            String checkPointIdsEnd = as.getEndCheckPointId();
            if(checkPointIdsStart.contains(cid) || checkPointIdsEnd.contains(cid)){
                return false;
            }
        }
        return true;
    }


    /**
     * 查询加班规则对象OverTimeRule 是否可以被删除
     * @param rid
     * @return true为可以删除（没有被引用），false为不能删除（被引用中）
     */
    public boolean confirmDeleteOverTimeRule(String rid){
        List<AttendanceGroupInfo> groupInfoList = iAttendanceGroupInfoService.selectAllAttendanceGroupInfo();
        for (AttendanceGroupInfo ag : groupInfoList
             ) {
            String ruleId = ag.getRulesId();
            if(ruleId.contains(rid)){
                return false;
            }
        }
        return true;
    }


    /**
     * 查询班次对象 AttendanceShiftInfo 是否可以被删除
     * @param sid
     * @return true为可以删除（没有被引用），false为不能删除（被引用中）
     */
    public boolean confirmDeleteShiftInfo(String sid){
        List<AttendanceGroupInfo> groupInfoList = iAttendanceGroupInfoService.selectAllAttendanceGroupInfo();
        for (AttendanceGroupInfo ag : groupInfoList
        ) {
            String shiftId = ag.getAttendanceShiftId();
            if(shiftId.contains(sid)){
                return false;
            }
        }
        return true;
    }


}
